<div ng-if="controller.valueDescriptor.union_field">
  <grr-form-proto-union value="controller.editedValue"
                        descriptor="controller.valueDescriptor" />
</div>

<div ng-if="!controller.valueDescriptor.union_field">
  <div class="form-group" ng-if="metadata.depth >= 2">
    <i class="nested-icon glyphicon" ng-click="controller.expanded = !controller.expanded"
       ng-class="{'glyphicon-plus': !controller.expanded, 'glyphicon-minus': controller.expanded}"></i>
  </div>

  <div ng-if="(metadata.depth === undefined || metadata.depth < 2 || controller.expanded)">

    <div ng-repeat="field in controller.valueDescriptor.fields |
                    filter:controller.regularFieldsOnly |
                    filter:controller.boundNotExplicitlyHiddenFields">
      <grr-form-proto-single-field value="controller.editedValue.value[field.name]"
                                   field="field"
                                   ng-if="!field.repeated">
      </grr-form-proto-single-field>

      <grr-form-proto-repeated-field value="controller.editedValue.value[field.name]"
                                     descriptor="controller.descriptors[field.type]"
                                     field="field"
                                     ng-if="field.repeated">
      </grr-form-proto-repeated-field>
    </div>

    <div ng-if="controller.hasAdvancedFields">
      <div>
        <label class="control-label">
          <a class="advanced-label"
             ng-click="controller.advancedShown = !controller.advancedShown">
            Advanced
          </a>
          <i class="advanced-icon glyphicon"
             ng-class="{'glyphicon-chevron-right': !controller.advancedShown,
                       'glyphicon-chevron-down': controller.advancedShown}"></i>
        </label>
      </div>
      <div class="clearfix"></div>

      <div class="advanced-controls" ng-show="controller.advancedShown">
        <div ng-repeat="field in controller.valueDescriptor.fields |
                        filter:controller.advancedFieldsOnly |
                        filter:controller.boundNotExplicitlyHiddenFields">
          <grr-form-proto-single-field value="controller.editedValue.value[field.name]"
                                       field="field"
                                       ng-if="!field.repeated">
          </grr-form-proto-single-field>

          <grr-form-proto-repeated-field value="controller.editedValue.value[field.name]"
                                         descriptor="controller.descriptors[field.type]"
                                         field="field"
                                         ng-if="field.repeated">
          </grr-form-proto-repeated-field>
        </div>
      </div>
    </div>
    <div class="clearfix"></div>

  </div>

</div>
